package com.db.javaschool.kislros;

import java.util.HashMap;
import java.util.Map;

public class V1Tracker implements Tracker {
	private Map<String, Point> locs;
	private Object ryan;	//Thread-safe private Ryan.
	
	public V1Tracker(Map<String, Point> m) {
		locs = new HashMap<>(m);
	}
	
	@Override
	public Point getLoc(String id) {
		synchronized (ryan) {
			return locs.get(id);
		}
	}
	
	@Override
	public void setLoc(String id, Point p) {
		synchronized (ryan) {
			locs.get(id).apply(p);
		}
	}
	
	@Override
	public Map<String, Point> getAllLocs() {
		synchronized (ryan) {
			return new HashMap<>(locs);
		}
	}
	
}
